#include "widget.h"
#include "ui_widget.h"
#include <QMouseEvent>
#include <QPoint>
#include <QWheelEvent>
#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QCursor cursor;
    cursor.setShape(Qt::OpenHandCursor);
    setCursor(cursor);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::mousePressEvent(QMouseEvent *event)
{
    if(event->button()!=Qt::LeftButton)
        return ;
    qDebug() << "[Widget::mousePressEvent]" << Qt::endl;
    QCursor cursor;
    cursor.setShape(Qt::ClosedHandCursor);
    QApplication::setOverrideCursor(cursor);
    relative_position = event->globalPosition().toPoint() - pos();

}

void Widget::mouseReleaseEvent(QMouseEvent *event)
{
    QApplication::restoreOverrideCursor();
}

void Widget::mouseDoubleClickEvent(QMouseEvent *event)
{
    if(event->button()!=Qt::LeftButton)
        return ;
    if(windowState() == Qt::WindowFullScreen){
        setWindowState(Qt::WindowNoState);
    }else{
        setWindowState(Qt::WindowFullScreen);
    }
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    qDebug() << event->button() << Qt::endl;
    qDebug() << "[Widget::mouseMoveEvent]" << Qt::endl;
    QPoint p1 = event->globalPosition().toPoint()-relative_position;
    move(p1);
}

void Widget::wheelEvent(QWheelEvent *event)
{
    if(event->button()!=Qt::LeftButton)
        return ;
    if(event->angleDelta().y() > 0){
        ui->textEdit->zoomIn();
    }else{
        ui->textEdit->zoomOut();
    }
}
